package just.stuff.morsels.util;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.IModel;

/**
 * Utility class for links with dynamic text content.  
 *
 * @param <T> Link model type
 */
public  class TextLink<T> extends BookmarkablePageLink<T> {

	private IModel<String> labelModel;
	
	public TextLink( String id, Class<? extends WebPage> pageClass, IModel<String> labelModel ) {
		this( id, pageClass, new PageParameters(), labelModel );
	}
	
	public TextLink( String id, Class<? extends WebPage> pageClass, PageParameters params, IModel<String> labelModel ) {
		super( id, pageClass, params );
		this.labelModel = labelModel;
	}
	
	public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
		replaceComponentTagBody(markupStream, openTag, labelModel.getObject() );
	}
	
}
